﻿// <copyright file="CustomerWindow.xaml.cs" company="FER">
//     Copyright (c) All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace NMBP_odb
{
    using System.ComponentModel;
    using System.Windows;

    using GalaSoft.MvvmLight.Messaging;

    using NMBP.Models;
    using NMBP.View.ViewModel;
    using NMBP.ViewModels;

    /// <summary>
    /// Interaction logic for CustomerWindow.xaml
    /// </summary>
    public partial class CustomerWindow : Window
    {
        /// <summary>
        /// Initializes a new instance of the CustomerWindow class
        /// </summary>
        public CustomerWindow()
        {
            InitializeComponent();
            this.Closing += this.CustomerWindow_Closing;

            Messenger.Default.Register<long>(
                this,
                "CloseCustomerWindow",
                (msg) =>
                    {
                        this.Close();
                    });

            Messenger.Default.Register<Customer>(
                this,
                "OpenEditCustomerWindow",
                (msg) =>
                    {
                        EditCustomerWindow editCustomerWindow = new EditCustomerWindow();
                        Messenger.Default.Send<Customer>(msg, "InitializeEditCustomer");
                        editCustomerWindow.Show();
                        this.Close();
                    });

            Messenger.Default.Register<Cart>(
                this,
                "OpenCartPurchaseWindow",
                (msg) =>
                    {
                        CartPurchaseWindow cartPurchaseWindow = new CartPurchaseWindow();
                        Messenger.Default.Send<Cart>(msg, "InitializeCartPurchase");
                        cartPurchaseWindow.Show();
                        this.Close();
                    });
        }

        /// <summary>
        /// Handles loading of menu window when expences window closes.
        /// </summary>
        /// <param name="sender">Object sender</param>
        /// <param name="e">Cancel event arguments</param>
        private void CustomerWindow_Closing(object sender, CancelEventArgs e)
        {
            Messenger.Default.Unregister(this);
            ViewModelLocator.ClearCustomerViewModel();
        }
    }
}
